//Iditarod Trail
//Amelia Bauer, Elise Eiden, Christine Gerardi, Taryn Green
//CSE 20212 2012
/*For naming new dogs
*/
#include "store.h"
#include "NameWindow.h"
#include <QtGui>
#include <QPushButton>
#include <QApplication>
#include <QGridLayout>
#include <QString>
#include <QLabel>
#include <iostream>
#include <QFont>
using namespace std;

//Constructor
NameWindow::NameWindow(QWidget *parent, int numDogsNorm, int numDogsDeluxe, Player *p):QWidget(parent)
{
	
	ply = new Player();
	ply = p;
	numDogsN = numDogsNorm;
	numDogsD = numDogsDeluxe;
	//Sets up window
	setWindowTitle(tr("Name your new dogs"));
	resize(120,120);

	//Adds and displays widgets
	QGridLayout *layout = new QGridLayout(this);
	QLabel *text = new QLabel(QString("Enter your new dog names: "));
	text->setFont(QFont("Times New Roman"));
	QLabel *arr[5];
		arr[0] = new QLabel(QString("Dog #1"));
		arr[1] = new QLabel(QString("Dog #2"));
		arr[2] = new QLabel(QString("Dog #3"));
		arr[3] = new QLabel(QString("Dog #4"));
		arr[4] = new QLabel(QString("Dog #5"));
	
		 arrEdit[0] = new QLineEdit(QString("Matt Damon"));
		 arrEdit[1] = new QLineEdit(QString("Matt Damon"));
		 arrEdit[2] = new QLineEdit(QString("Matt Damon"));
		 arrEdit[3] = new QLineEdit(QString("Matt Damon"));
		 arrEdit[4] = new QLineEdit(QString("Matt Damon"));
	QLabel *deluxeLabel[5];
		deluxeLabel[0] = new QLabel(QString("Deluxe"));
		deluxeLabel[1] = new QLabel(QString("Deluxe"));
		deluxeLabel[2] = new QLabel(QString("Deluxe"));
		deluxeLabel[3] = new QLabel(QString("Deluxe"));
		deluxeLabel[4] = new QLabel(QString("Deluxe"));

	QPushButton *ok = new QPushButton(QString("OK"));
	for(int i = 0; i<numDogsNorm; i++)
	{
		layout->addWidget(arr[i], i+1, 1);
		layout->addWidget(arrEdit[i], i+1, 2);
	}
	for(int i = numDogsNorm; i<numDogsDeluxe+numDogsNorm; i++)
	{
		layout->addWidget(arr[i], i+1, 1);
		layout->addWidget(arrEdit[i], i+1, 2);
		layout->addWidget(deluxeLabel[i], i+1,0);
	}

	layout->addWidget(text,0,2);
	layout->addWidget(ok,10,1);
	setLayout(layout);

	//Connects buttons to slots
	connect(ok, SIGNAL(clicked()), this, SLOT(done()));

}

//Closes the pop up window
void NameWindow:: done()
{
	string nameTemp;
	int index;
	//Adds proper number of text boxes to change names 
	for(int i = 0; i<numDogsN + numDogsD; i++)
	{
		nameTemp = arrEdit[i]->text().toStdString();	
		index = ply->getNumDog()-(numDogsN+numDogsD)+i;
		ply->setNameDogs(index, nameTemp);
	}
	this->hide();
}


